#include <sys/ipc.h>
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/shm.h>
#include <sys/types.h>
#include <unistd.h>

typedef struct
{
    char name;
    int age;
}people;

static people addr[20];

int main(int argc,char **argv)
{
     int shm_id,i;
     char temp_char;
     people *p_map;

     shm_id=shmget(IPC_PRIVATE,4096,IPC_CREAT);
     if(shm_id<0){
         perror("shmget error");
     }
     p_map = (people*)shmat(shm_id, addr, 0);
     if(p_map == NULL){
         perror("shmmat error");
     }
     temp_char = 'a';
     for(i=0;i<10;i++)
     {
        (p_map+i)->name = temp_char;
		printf("i = %d\n", i);
        (p_map+i)->age = 20+i;
		printf("i = %d\n", i);     
        temp_char+=1;
		printf("i = %d\n", i);
     }
     if(shmdt(p_map)<0)
    perror("detach error");
     
     return 0;
}

